from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

import api
import mcp_tools
from scheduler import scheduler

app = FastAPI()
app.include_router(api.router)
app.include_router(mcp_tools.router)


@app.on_event("startup")
def startup():
    scheduler.start()


@app.on_event("shutdown")
def shutdown():
    scheduler.shutdown()


# Add MCP server to the FastAPI app
mcp = FastApiMCP(
    app,
    name="Products API MCP",
    description="Search products from local mongodb",
    include_tags=["search"],
    # describe_full_response_schema=True,  # Describe the full response JSON-schema instead of just a response example
    # describe_all_responses=True,  # Describe all the possible responses instead of just the success (2XX) response
)

# Mount the MCP server to the FastAPI app
mcp.mount()

# uvicorn main:app --port=11015 --reload

# How do I test my FastApiMCP server is working?
# https://fastapi-mcp.tadata.com/getting-started/FAQ#how-do-i-test-my-fastapimcp-server-is-working%3F

if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=11015)
